package com.lagou.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.pojo.Article;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/toIndex")
    public String toIndex(Model model, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<Article> articleList=articleService.getAllArticle();
        PageInfo articlePageList = new PageInfo(articleList);
        model.addAttribute("articleList",articleList);
        //处理分页信息
        model.addAttribute("pages",articlePageList);
        return "index";
    }


}
